//
//  RootTabBarController.m
//  快乐一点通
//
//  Created by cjp on 16/7/16.
//  Copyright © 2016年 cjp. All rights reserved.
//

#import "RootTabBarController.h"

#import "CJPNavigationController.h"
#import "EntertainmentViewController.h"
#import "MovieViewController.h"
#import "FourthTableViewController.h"
#import "UserViewController.h"

@interface RootTabBarController ()

@end

@implementation RootTabBarController

+ (void)initialize{
    /*
     通过appearance 统一设置UITabBarItem的文字属性
     后面带有UI_APPEARANCE_SELECTOR的方法,都可以通过appearce对象来统一设置
     */
    
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    // 设置字体
    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    // 设置字体颜色
    attrs[NSForegroundColorAttributeName] = [UIColor grayColor];
    
    NSMutableDictionary *selectAttrs = [NSMutableDictionary dictionary];
    // 统一设置选中时的字体
    selectAttrs[NSFontAttributeName] = attrs[NSFontAttributeName];
    // 选中时字体的颜色
    selectAttrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
    
    // 添加到tabBar上
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:attrs forState:(UIControlStateNormal)];
    [item setTitleTextAttributes:selectAttrs forState:(UIControlStateSelected)];
}

- (void)viewDidLoad{
    [super viewDidLoad];
    
    // 添加子控制器
//    [self setupChildVC:[[XMGMeViewController alloc] init] title:@"我" image:@"tabBar_me_icon" selectedImage:@"tabBar_me_click_icon"];
    
    [self setupChildVC:[[EntertainmentViewController alloc]init] title:@"娱乐头条" image:@"搞笑段子-1" selectedImage:@"搞笑段子"];
    
    [self setupChildVC:[[MovieViewController alloc] init] title:@"影视资讯" image:@"视频-1" selectedImage:@"视频"];
    
    [self setupChildVC:[[FourthTableViewController alloc] init] title:@"搞笑动漫" image:@"视频(1)" selectedImage:@"用户"];

    UIViewController *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"UserViewController"];
    [self setupChildVC:vc title:@"我的" image:@"我的-1" selectedImage:@"我的"];
    
}

/** 初始化子控制器 */
- (void)setupChildVC:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage{
    // 设置文字和图片
    vc.tabBarItem.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:image];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    vc.view.backgroundColor = [UIColor colorWithRed:211/255.0 green:231/255.0 blue:247/255.0 alpha:1.0];
    
    // 包装一个导航控制器,添加导航控制器为tabBarController的子控制器
    CJPNavigationController *nav = [[CJPNavigationController alloc]initWithRootViewController:vc];
    [self addChildViewController:nav];
    
}

@end
